package twi.query.template2;

import java.awt.Component;
import java.util.ArrayList;

import javax.swing.JComponent;

import jtools.gui.DefaultLayoutNode;
import jtools.gui.TreeLayoutNode;
import twi.Utils;
import twi.query.template.NameFactory;
import twi.query.template2.view.ClassChooseListener;
import twi.query.template2.view.IndividualView;
import twi_project.TWI;

import com.hp.hpl.jena.ontology.OntClass;

public class IndividualNode extends DefaultLayoutNode implements TemplateNode, ClassChooseListener{

	
	private String className;
	private TemplateNode parent;
	private Template template;
	private transient IndividualView view = null;
	private String variableName = null;
	private String individualName;
	
	public IndividualNode(String className, TemplateNode par, Template template){
		super(par);
		this.className = className;
		this.parent = par;
		this.template = template;
	}
	@Override
	public JComponent createView(boolean edit) {
		if (this.view != null)
			return this.view;
		ArrayList<OntClass> indiList = Utils.listClasses(TWI.getInstance().getOntologieModel().getOntClass(className), false, true);
		ArrayList<String> s = new ArrayList<String>();
		for (int i = 0; i < indiList.size(); i++)
			s.add(Utils.getLocalName(indiList.get(i)));
		this.view = new IndividualView(s, this);
		view.setVisible(true);
		return view;
	}

	@Override
	public ArrayList<String> getAllPropertys() {
		return new ArrayList<String>();
	}

	@Override
	public ArrayList<TemplateNode> getChild(String propertyName) {
		return null;
	}

	@Override
	public String getOntClassName() {
		return individualName;
	}

	@Override
	public TemplateNode getParent() {
		return parent;
	}

	@Override
	public String getPropertyName() {
		return null;
	}

	@Override
	public String getVariableName() {
		return this.variableName;
	}

	@Override
	public ArrayList<String> getVisiblePropertys() {
		return new ArrayList<String>();
	}

	@Override
	public boolean isVisible() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void rekursiveMinimize() {
		// TODO Auto-generated method stub

	}

	@Override
	public void addChild(TreeLayoutNode node) {
		// TODO Auto-generated method stub

	}

	@Override
	public void deepRemove() {

	}
	@Override
	public Component getComponent() {
		return createView(true);
	}
	@Override
	public void chooseClass(String className) {
		this.individualName = className;
		this.variableName = NameFactory.createNameFromClassName("indi");
	}
	@Override
	public void maximize() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void init(TemplateNode parent, boolean edit) {
		this.setParent(parent);		
	}
	@Override
	public boolean isOptional() {
		return false;
	}
	@Override
	public boolean showVariable() {
		return this.view.showVariable();
	}
	@Override
	public ArrayList<TemplateNode> getIndividualList() {
		return new ArrayList<TemplateNode>();
	}
	@Override
	public PropertyNode getPropertyNode(String prop) {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public String getPropertyValue(String prop) {
		// TODO Auto-generated method stub
		return null;
	}


}
